<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('选择租房时间')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form enctype="multipart/form-data" class="form-horizontal m" id="form-addLoan-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">租房时长（月）：</label>
                <div class="col-sm-8">
                    <input id="timeLen" name="timeLen" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input id="beginDate" name="beginTime"  readonly="readonly" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        let houseId = [[${houseId}]];
        var prefix = ctx + "admin/apply"

        $("#form-addLoan-add").validate({
            focusCleanup: true,
            rules: {
                timeLen: {
                    digits: true,
                    max: 99,
                    min: 1
                },
            },
        });

        function submitHandler() {
            if ($.validate.form()) {
                var date = $('#beginDate').val();
                var timeLen = $('#timeLen').val();
                $.ajax({
                    url:prefix + '/add',
                    type:'post',
                    data:{houseId:houseId,date:date,timeLen:timeLen},
                    dataType:'json',
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.successTabCallback(result);
                    }
                });
            }
        }

        $("input[name='beginTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            startDate: new Date(),
            autoclose: true
        });


    </script>
</body>
</html>